package com.feemanage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cfg.domain.ClaimProjectShow;
import com.common.annotation.Anonymous;
import com.common.core.domain.R;
import com.common.core.page.PageDomain;
import com.common.core.page.TableDataInfo;
import com.common.utils.poi.ExcelUtil;
import com.common.validate.add;
import com.common.validate.edit;
import com.feemanage.domain.BizCwIncome;
import com.feemanage.domain.bo.FundsFeeShowBo;
import com.feemanage.domain.vo.BizCwIncomeVo;
import com.feemanage.domain.vo.ClaimBudgetFeeShowVo;
import com.feemanage.domain.vo.ClaimFeeShowVo;
import com.feemanage.domain.vo.ClaimManageFeeVo;
import com.feemanage.service.IcWIncomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import java.util.Arrays;
import java.util.List;

/**
 * 银行到款
 */
@Api(tags="银行到款")
@RestController
@RequestMapping("/feemanage/cwincome")
public class cWIncomeController {

    @Autowired
    private IcWIncomeService baseService;

    /**
     * 查询列表
     * @param pageDomain
     * @param cwIncome
     * @return
     */
    @ApiOperation("查询列表")
    @GetMapping("/list")
    public TableDataInfo list(PageDomain pageDomain, BizCwIncome cwIncome){
        IPage<BizCwIncomeVo> page = baseService.selectList(pageDomain,cwIncome);
        return TableDataInfo.build(page.getRecords(),page.getTotal());
    }

    @ApiOperation("导出银行到款")
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody PageDomain pageDomain, @RequestBody BizCwIncome cwIncome)
    {
        List <BizCwIncomeVo> list = baseService.selectExportList(pageDomain,cwIncome);
        ExcelUtil<BizCwIncomeVo> util = new ExcelUtil<>(BizCwIncomeVo.class);
        util.exportExcel(response, list, "银行到款","银行到款");
    }

    /**
     * 查询详情
     * @param cwIncome
     * @return
     */
    @ApiOperation("查询详情")
    @GetMapping("/getInfo")
    public R<BizCwIncomeVo> getInfo(BizCwIncome cwIncome){
        return R.ok(baseService.selectOne(cwIncome));
    }

    /**
     * 新增
     * @param cwIncome
     * @return
     */
    @ApiOperation("新增")
    @PostMapping("/add")
    public R<Void> addCwIncome(@Validated(add.class) @RequestBody  BizCwIncome cwIncome){
        boolean result = baseService.addCwIncome(cwIncome);
        return result ? R.ok() : R.fail();
    }

    /**
     * 编辑
     * @param cwIncome
     * @return
     */
    @ApiOperation("编辑")
    @PostMapping("/edit")
    public R<Void> editCwIncome(@Validated(edit.class) @RequestBody  BizCwIncome cwIncome){
        boolean result = baseService.editCwIncome(cwIncome);
        return result ? R.ok() : R.fail();
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping("/remove/{ids}")
    public R<Void> remove( @NotEmpty(message = "主键不能为空") @PathVariable String[] ids)
    {
        boolean result = baseService.delCwIncome(Arrays.asList(ids),true);
        return result ? R.ok() : R.fail();
    }


    /**
     * 检查项目是否满足认领要求
     * @return
     */
    @ApiOperation("检查项目,cwIncomeClaim--当前项目有未结束的认领经费，不能进行xxxx！ " +
            "alteration--当前项目有未结束的调账经费，不能进行xxxx！ " +
            "claimBack --当前项目有未结束的退回经费，不能进行xxxx！ " +
            "noProBudget -- 当前项目没有登记预算，请补充预算后再xxx " +
            "noIncome--该项目没有到账信息,无法进行xx!")
    @GetMapping("/checkproject")
    public String  checkProject(@NotEmpty(message = "未选择要认领的项目！") String projectId)
    {
        String checkProjectResult = baseService.checkProject(projectId);
        return checkProjectResult;
    }

    /**
     * 项目筛选列表
     * @return
     */
    @ApiOperation("获取项目筛选列表")
    @GetMapping("/selectVproject")
    public TableDataInfo selectVproject(PageDomain pageDomain, ClaimProjectShow showVo)
    {
        IPage<ClaimProjectShow> page = baseService.selectVproject(pageDomain,showVo);
        return TableDataInfo.build(page.getRecords(),page.getTotal());
    }

    /**
     * 获取认领和项目相关的数据
     * @param showBo
     * @return
     */
    @ApiOperation("获取认领和项目相关的数据")
    @GetMapping("/getClaimFeeInfo")
    public R<ClaimFeeShowVo> getClaimFeeInfo(FundsFeeShowBo showBo)
    {
        return R.ok(baseService.selectClaimFeeInfo(showBo));
    }

    @ApiOperation("获取项目额度经费")
    @GetMapping("/getSplitBudgetFee")
    public R<List<ClaimBudgetFeeShowVo>> seletcBudegtFee(FundsFeeShowBo showBo){
        return R.ok(baseService.seletcBudegtFee(showBo));
    }

    @ApiOperation("获取项目管理费")
    @GetMapping("/getSplitManageFee")
    public R<List<ClaimManageFeeVo>> selectManageFee(FundsFeeShowBo showBo){
        return R.ok(baseService.selectManageFee(showBo));
    }
}
